home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16943 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.ti.com!usenet
  2. From: Chuach@dlep1.itg.ti.com (Chua Chye Heng)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: HELP!! How to correctly pass member functions to a C function???
  5. Date: Wed, 10 Apr 1996 08:02:25 GMT
  6. Organization: Texas Instruments
  7. Message-ID: <4kfslu$s1t@tilde.csc.ti.com>
  8. References: <4kf534$csn@tilde.csc.ti.com>
  9. NNTP-Posting-Host: 137.167.42.30
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Chuach@dlep1.itg.ti.com (Chua Chye Heng) wrote:
  13.  
  14. A little more info:
  15.  
  16. 1. when I declared the method to be static, the calling went thro'
  17. But I am unable to call non-static members in the static method
  18.  
  19. 2. I declared a C function wrapper to indirectly call the method.
  20. However, the this pointer is no longer valid when the method is being
  21. called. I have to save the this pointer and cast it to the right class
  22. type in order to call other member within that method.
  23.  
  24. Anyone have a better solution??
  25.  
  26. >Hi,
  27.  
  28. >I need to use a function in a c library which search some database and
  29. >invoke the user defined function to process them in my c++ program.
  30. >    /* c function prototype */
  31. >    search( int (*norm_func)(), int (*err_func)());
  32.  
  33. >My class definitions are as follows:
  34. >extern "C" {
  35. >#include "C-function.h"
  36. >}
  37.  
  38. >class base {
  39. >...
  40. >public:
  41. >    int process();
  42. >    virtual int good_handle( data* pData ) = 0;
  43. >    virtual int bad_handle( char* msg )=0;
  44. >}
  45.  
  46. >class derived : public base {
  47. >...
  48. >public:
  49. >    int good_handle( data* pData );
  50. >    int bad_handle( char* msg);
  51. >}
  52.  
  53. >I use the process method in the base class to invoke the C function
  54. >like this:
  55. >    search ( (int(*)())this->good_handle, (int(*)())this->bad_handle);
  56.  
  57. >When the program executes, the good_handle method in the derived class
  58. >did get called. BUT the data* pData points to some "&^%$#" instead!!
  59. >I did try to use a normal C program to test out the library and it is
  60. >working fine.
  61.  
  62. >Can some kind people help me out of this?? My project schedule is
  63. >falling on me..... HELP
  64.  
  65. >Deeply appreciate any hints or help..
  66.  
  67. >BTW, I also try to use a normal C function to wrap around the two
  68. >method but it also fail
  69. >    base* pBase;
  70. >    int good( ...) { pBase->good_handle(...); }
  71. >    int bad(...) { pBase->bad_handle(...); }
  72. >        and called them in process as: 
  73. >        search (good_handle, bad_handle);
  74.  
  75.  
  76. >===========================================================
  77. >Chye Heng
  78. >Email: Chuach@dlep1.itg.ti.com
  79. >Voice: 065-2902460
  80.  
  81.  
  82.  
  83.  
  84. ===========================================================
  85. Chye Heng
  86. Email: Chuach@dlep1.itg.ti.com
  87. Voice: 065-2902460
  88.  
  89.  
  90.